package com.game.majiang.vo;

import java.sql.SQLException;
import java.sql.Types;

import javax.sql.rowset.CachedRowSet;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;

import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class UnionapplyVo {
	
	int unionid;
	String unionname;
	int applyid;
	int status;
	int type;
	
	public  void  insertUnionapply() {
		String cmdText = "insert into unionapply(unionid,unionname,applyid,status,createtime,type)values(?,?,?,?,now(),?)";
		Parameter p1 = new Parameter(Types.INTEGER, unionid, ParameterType.Input);
		Parameter p2 = new Parameter(Types.VARCHAR, unionname, ParameterType.Input);
		Parameter p3 = new Parameter(Types.INTEGER, applyid, ParameterType.Input);
		Parameter p4 = new Parameter(Types.INTEGER, status, ParameterType.Input);
		Parameter p5 = new Parameter(Types.INTEGER, type, ParameterType.Input);
		SqlHelperwrite.execute(cmdText,p1,p2,p3,p4,p5);
	}
	
	public int checkapply(int type) {
		String cmdText = "select id from unionapply where unionid=? and status =0 and type="+type+" ";
		Parameter p1 = new Parameter(Types.INTEGER, unionid, ParameterType.Input);
		Object obj=SqlHelper.execScalar(cmdText,p1);
		if(obj!=null){
			return (int)obj;
		}else{
			return 0;
		}
	} 
	public static int selectapplyunion(int id) {
		int unionid=0;
		String cmdText = "select unionid from unionapply where id =? ";
		Parameter p1 = new Parameter(Types.INTEGER, id, ParameterType.Input);
		CachedRowSet rs = SqlHelper.getResultSet(cmdText,p1);
		try {
			if (rs.next()) 
			{  
				unionid=rs.getInt(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return unionid;
	} 
	
	public static void updateapplystatus(int id,int status) 
	{
		String cmdText = "UPDATE unionapply set status=? WHERE id=?";
		Parameter p1 = new Parameter(Types.INTEGER,status, ParameterType.Input);
		Parameter p2 = new Parameter(Types.INTEGER,id, ParameterType.Input);
		SqlHelperwrite.execute(cmdText, p1,p2);
	}
	public static int selectapplyid(int id) {
		int applyid=0;
		String cmdText = "select applyid from unionapply where id =? ";
		Parameter p1 = new Parameter(Types.INTEGER, id, ParameterType.Input);
		CachedRowSet rs = SqlHelper.getResultSet(cmdText,p1);
		try {
			if (rs.next()) 
			{  
				applyid=rs.getInt(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return applyid;
	} 
}
